package com.dominator.controller.api;

import com.dominFramework.core.utils.JsonUtils;
import com.dominator.enums.ReqEnums;
import com.dominator.service.ApiCommonService;
import com.dominator.utils.api.ApiMessage;
import com.dominator.utils.exception.ApiException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class ApiLogController {


    @Autowired
    HttpServletRequest request;


    @Autowired
    ApiCommonService apiCommonService;

    /**
     * 测试
     *
     * @param paramStr
     * @return
     */
    @PostMapping("/test")
    public ApiMessage postTest(@RequestParam String paramStr) {
        ApiMessage msg;
        try {
            msg = apiCommonService.test(JsonUtils.toDto(paramStr));
        } catch (ApiException e) {
            msg = new ApiMessage(e.getCode(), e.getMessage());
        } catch (Exception e) {
            msg = new ApiMessage(ReqEnums.SYS_ERROR.getCode(), ReqEnums.SYS_ERROR.getMsg());
            e.printStackTrace();
        }
        return msg;

    }
}
